package io.renren.modules.nuaa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.constant.Constant;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.nuaa.dao.TAddressDao;
import io.renren.modules.nuaa.dto.TAboutDTO;
import io.renren.modules.nuaa.dto.TAddressDTO;
import io.renren.modules.nuaa.entity.TAboutEntity;
import io.renren.modules.nuaa.entity.TAddressEntity;
import io.renren.modules.nuaa.service.TAddressService;
import io.renren.modules.security.user.SecurityUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 地址
 *
 * @author Mark sunlightcs@gmail.com
 * @since 3.0 2024-03-04
 */
@Service
public class TAddressServiceImpl extends CrudServiceImpl<TAddressDao, TAddressEntity, TAddressDTO> implements TAddressService {

    @Override
    public QueryWrapper<TAddressEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<TAddressEntity> wrapper = new QueryWrapper<>();

        String title = (String)params.get("title");
        wrapper.like(StringUtils.isNotBlank(title), "title", title);
        String address = (String)params.get("address");
        wrapper.like(StringUtils.isNotBlank(address), "address", address);

        return wrapper;
    }


    @Override
    public List<TAddressEntity> queryByCatgegoryId(Integer categoryId) {
        if (categoryId != null) {
            List<TAddressEntity> addressEntity = baseDao.selectList(
                    new QueryWrapper<TAddressEntity>()
                            .eq("category_id", categoryId)
                            .orderByAsc("sort")
            );
            return addressEntity;
        }
        return null;
    }


}